/*
 * @(#)PersonalRelationshipTransformer.java
 * Date 2013-08-17
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.pix.transformer;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import org.hl7.v3.PRPAMT201301UV02PersonalRelationship;

import us.hornerscorners.lamppost.exception.ServiceActionException;

import us.hornerscorners.lamppost.hl7v3common.utils.HL7Utils;

import us.hornerscorners.lamppost.model.patient.PersonalRelationship;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;


/**
 *
 * @author jim
 */
@ApplicationScoped
public class PersonalRelationshipTransformer
        extends AbstractTransformer<PRPAMT201301UV02PersonalRelationship,
            PersonalRelationship> {

    /** Field description */
    @Inject
    private CodedElementTransformer codedElementTransformer;

    /** Field description */
    @Inject
    private InstanceIdentifierTransformer instanceIdentifierTransformer;

    /** Field description */
    @Inject
    private PersonNameTransformer personNameTransformer;

    /** Field description */
    @Inject
    private PhoneNumberTransformer phoneNumberTransformer;

    /** Field description */
    @Inject
    private PostalAddressTransformer postalAddressTransformer;

    /**
     * Constructs ...
     *
     */
    public PersonalRelationshipTransformer() {
        super();
    }

    /**
     * Method description
     *
     *
     * @param prpaRelationship
     *
     * @return
     */
    @Override
    public PersonalRelationship transform(
            PRPAMT201301UV02PersonalRelationship prpaRelationship)
            throws ServiceActionException {

        PersonalRelationship result = null;

        if (prpaRelationship != null) {

            result = new PersonalRelationship();
            result.setEffectiveTime(
                HL7Utils.toEffectiveTime(prpaRelationship.getEffectiveTime()));

            result.getIdentifiers().addAll(
                this.instanceIdentifierTransformer.transform(prpaRelationship.getId()));

            result.getPersonNames().addAll(
                this.personNameTransformer.transformCOCTMT030007UVPerson(
                    prpaRelationship.getRelationshipHolder1()));

            result.getPhoneNumbers().addAll(
                this.phoneNumberTransformer.transform(prpaRelationship.getTelecom()));

            result.getPostalAddresses().addAll(
                this.postalAddressTransformer.transform(prpaRelationship.getAddr()));

            result.setRelationshipCode(
                this.codedElementTransformer.transform(prpaRelationship.getCode()));

            result.setStatusCode(
                this.codedElementTransformer.transform(prpaRelationship.getStatusCode()));
        }

        return result;
    }
}
